package com.jin.blog.pojo;

import java.util.Arrays;
import java.util.List;

import org.jsoup.Jsoup;

import com.jfinal.plugin.activerecord.Model;
import com.jin.blog.core.BlogConstants;

public class Article extends Model<Article> {

	private static final long serialVersionUID = 6298774837273546513L;
	public static final Article dao = new Article();

	public static final String ID = "id";
	public static final String TITLE = "title";
	public static final String CREATE_DATE_TIME = "createDateTime";
	public static final String TYPE = "type";
	public static final String URL = "url";
	public static final String VIEWCOUNT = "viewCount";
	public static final String CONTENT = "content";
	public static final String REPLYCOUNT = "replyCount";
	public static final String TAGS = "tags";
	public static final String PROJECT_ID = "projectId";

	private String _createDateTime;

	public String get_createDateTime() {
		if (null == _createDateTime) {
			_createDateTime = BlogConstants.format
					.format(getTimestamp(CREATE_DATE_TIME));
		}
		return _createDateTime;
	}

	private String brief;

	public String getBrief() {
		if (null == brief) {
			String cnt = Jsoup.parse(getStr(CONTENT)).text();
			brief = cnt.substring(0, cnt.length() > 200 ? 200 : cnt.length());
		}
		return brief;
	}

	private List<String> _tags;

	public List<String> get_tags() {
		if (null == _tags) {
			_tags = Arrays.asList(getStr(TAGS).split(","));
		}
		return _tags;
	}

	private Project _project;

	public Project get_project() {
		if (_project == null) {
			_project = Project.dao.findById(getInt(PROJECT_ID));
		}
		return _project;
	}

}
